/**************************************************************************************************
  Filename:       otaservice.h
  Revised:         
  Revision:        

  Description:    This file contains the OTA profile definitions and
                  prototypes.

 **************************************************************************************************/

#ifndef OTASERVICE_H
#define OTASERVICE_H

#ifdef __cplusplus
extern "C"
{
#endif

/*********************************************************************
 * INCLUDES
 */

/*********************************************************************
 * CONSTANTS
 */

#define CS_OTA_BASE_UUID_128(uuid)		0x23, 0xD1, 0xBC, 0xEA, 0x5F, 0x78, 0x23, 0x15, 0xDE, 0xEF, 0x12, 0x12, \
										LO_UINT16(uuid), HI_UINT16( uuid ), 0x00, 0x00
	
// Profile Parameters
#define OTAPROFILE_CTL_POINT_CHAR                   0
#define OTAPROFILE_PACKET_CHAR                   	1
  
// OTA Profile Service UUID
#define OTAPROFILE_SERV_UUID               		0x1530
    
// OTA Profile Characteristics UUID
#define OTAPROFILE_CTL_POINT_CHAR_UUID			0x1531		//OTA Control Point: 0x8EC90001-F315-4F60-9FB8-838830DAEA50
#define OTAPROFILE_PACKET_CHAR_UUID				0x1532		//OTA Packet: 0x8EC90002-F315-4F60-9FB8-838830DAEA50
#define OTAPROFILE_REV_CHAR_UUID				0x1534		//OTA Revision

// OTA Profile Characteristics length
#define OTAPROFILE_CTL_POINT_CHAR_LEN			20
#define OTAPROFILE_PACKET_CHAR_LEN				20
  
// OTA Profile Services bit fields
#define OTAPROFILE_SERVICE               0x00000001

#define OTAPROFILE_CTL_POINT_HANDLE					2
#define OTAPROFILE_CTL_POINT_CFG_HANDLE				3

/*********************************************************************
 * TYPEDEFS
 */
enum{
	OTA_EVT_NULL = 0,
	OTA_EVT_CONTROL = 1,
	OTA_EVT_DATA,
	OTA_EVT_CONNECTED,
	OTA_EVT_DISCONNECTED,
	OTA_EVT_NOTIF_ENABLE,
	OTA_EVT_NOTIF_DISABLE,
};


typedef struct{
  uint8_t 	type;
  uint8_t   len;
  uint8_t* 	data;
}OtaEvt_t;
  
/*********************************************************************
 * MACROS
 */

/*********************************************************************
 * Profile Callbacks
 */
typedef void (*pfnOtaProfileChangeCB_t)( OtaEvt_t *pEvt);

typedef struct
{
  pfnOtaProfileChangeCB_t        pfnOTAProfileChange;  // Called when characteristic value changes
} otaProfileCBs_t;

    

/*********************************************************************
 * API FUNCTIONS 
 */


/*
 * OTAProfile_AddService- Initializes the OTA Profile service by registering
 *          GATT attributes with the GATT server.
 *
 * @param   services - services to add. This is a bit map and can
 *                     contain more than one service.
 */

extern bStatus_t OTAProfile_AddService( uint32 services );

/*
 * OTAProfile_RegisterAppCBs - Registers the application callback function.
 *                    Only call this function once.
 *
 *    appCallbacks - pointer to application callbacks.
 */
extern bStatus_t OTAProfile_RegisterAppCBs( otaProfileCBs_t *appCallbacks );

/*
 * OTAProfile_SetParameter - Set a OTA Profile parameter.
 *
 *    param - Profile parameter ID
 *    len - length of data to right
 *    value - pointer to data to write.  This is dependent on
 *          the parameter ID and WILL be cast to the appropriate 
 *          data type (example: data type of uint16 will be cast to 
 *          uint16 pointer).
 */
extern bStatus_t OTAProfile_SetParameter( uint8 param, uint8 len, void *value );
  
/*
 * OTAProfile_GetParameter - Get a OTA Profile parameter.
 *
 *    param - Profile parameter ID
 *    value - pointer to data to write.  This is dependent on
 *          the parameter ID and WILL be cast to the appropriate 
 *          data type (example: data type of uint16 will be cast to 
 *          uint16 pointer).
 */
extern bStatus_t OTAProfile_GetParameter( uint8 param, void *value );

extern bStatus_t OTAProfile_Notify(attHandleValueNoti_t *pNotify);


/*********************************************************************
*********************************************************************/

#ifdef __cplusplus
}
#endif

#endif /* SIMPLEGATTPROFILE_H */
